#!/bin/sh +x
#
# IOXperts Uninstaller.sh
#
# Written by : Ian Keck		Dec 2004-Jan 2005
#
#
# Usage: IOXpertsUninstaller <method> [-volume <volumeName>] [-bin <bindir>] [-scripts <scriptdir>] [-show] [-installer] [-verbose] <itemToRemove> ...
#
# Valid methods are: trash, mvmac, remove, show
#	trash					uses a tool to move files to the trash, appending 'copy <n>' as appropriate
#   mvmac					uses mvmac to move files to the trash, but currently doesn't append 'copy <n>' to the names.
#	remove					uses the rm command
#   show					lists the files to be removed
#
# Options are as follows
#	-volume <volumename>	remove products on volume named /Volumes/<volumename>, default = boot volume
#							NOTE - trash methods may not work, remove and show options should work.
#	-bin	<bindir>		location of bin directory - containing all tools needed by the removal script - default is .
#	-scripts <scriptdir>	location of scripts dir - containing all scripts that need to be sourced - default is .
#	-show					echo commands that would be performed instead of performing them
#	-installer				uninstaller is running in the installer
#	-verbose				echo more stuff
#	-removeprefs			remove preference files for specified components
#	-clearprefs				erase specific preferences for specified components
#	-removeinstaller		remove installer receipts for specified components
#
# Names of items which may be removed
#
#	The following names are composite items
#		webcam, usbwebcam = ioxperts usb webcam drivers
#		iidc			  = ioxperts iidc firewire drivers
#		wireless		  = ioxperts wireless drivers
#		still			  = ioxperts still camera drivers
#		industrial		  = ioxperts industrial camera drivers
#		logitech		  = logitech webcam drivers
#		stmicro			  = stmicro still drivers
#		ioxperts		  = webcam, iidc, wireless, still and industrial
#		all				  = ioxperts and logitech
#
#	The following names are individual items
#		shared			  = video shared
#		register		  = purchase and register
#		dm				  = dm
#		sgpanel			  = sgpanel
#		codecs			  = standard ioxperts codecs
#		industrial-codecs  = bayer codecs
#		video-kexts		  = ioxperts video kext
#		logitech-kexts	  = logitech kexts
#		webcam-vdigs
#		iidc-vdigs
#		industrial-vdigs
#		logitech-vdigs
#		wireless-kexts
#		still-capture
#		stmicro-still-capture
#		
#
#
# --------------------------------------------------------------------------
# Required Tools
#
#	MoveToTrash
#	MvMac
#	KillDeviceMonitor
#   KillSessionMonitor
#	ComponentTool
#
# Required Scripts
#	UninstallerTools.sh
#
# Unix Tools
#   rm
#	kill
#	ls
#	echo
#   sed
#
# ---------------------------------------------------------------------------
#
# Expected Behavior
#	In an installer      - remove everything that will conflict with what will be replacing it.
#	Outside an installer - only allow top level - composite components
#						 - don't remove components shared by other installed components.
#	Remove				 - doesn't fail if something isn't there.
#	Test for IsInstalled - if only one item of a subsystem is there it's installed for the purposes
#						   of the uninstaller
#
# Problems - need to be able to determine what is installed.
#		   - need to be able to determine what not to remove - those items used by other installed components.
#		   - can do all this in sh, easier to do in python.
#
#
# ---------------------------------------------------------------------------
# 
#
# TODO - write a function that saves a copy of device keys to ~
# TODO - write a script that restores these device keys from ~
# TODO - move files to trash in structure corresponding to the installation structure.
#		 how would this work with multiple installs and 'copy <n>' appended?
# TODO - move to appropriate trash on another boot volume - may need to specify user and trash folder explicitly
#

# echo commands off  (set -v echos commands, set +v doesn't)
# xtrace on  (set -x shows what was executed, set +x doesn't)

# ----------------------------------------------------------------------
# Process Args

HOW=$1
WHAT=()
VOLUME=""
BINDIR=""
SCRIPTDIR="."
VERBOSE=0
SHOW=0

INSTALLER=0
OPTION_REMOVE_INSTALLER=0
OPTION_REMOVE_PREFERENCES=0
OPTION_CLEAR_PREFERENCES=0

# -----------------------------------------------------------------------

shift
while (( 0 < $# ))
do
	arg="$1"
	
	if [[ "${arg}" == "-volume" || "${arg}" == "-v" ]]
	then
		shift
		VOLUME="$1"
		
	elif [ "${arg}" == "-bin" ]
	then
		shift
		BINDIR="$1"
		
	elif [ "${arg}" == "-scripts" ]
	then
		shift
		SCRIPTDIR="$1"
		
	elif [ "${arg}" == "-installer" ]
	then
		INSTALLER=1
		
	elif [ "${arg}" == "-removeinstaller" ]
	then
		OPTION_REMOVE_INSTALLER=1
		
	elif [ "${arg}" == "-removeprefs" ]
	then
		OPTION_REMOVE_PREFERENCES=1
		
	elif [ "${arg}" == "-clearprefs" ]
	then
		OPTION_CLEAR_PREFERENCES=1
		
	elif [[ "${arg}" == "-show" || "${arg}" == "-showonly" ]]
	then
		SHOW=1
		
	elif [ "${arg}" == "-verbose" ]
	then
		VERBOSE=1
		
	else
		# add arg to list of what to take action on.
		WHAT=( "${WHAT[@]}" "${arg}" )
	fi
	
	shift
done

# -----------------------------------------------------------------------

if [ "${#WHAT}" -eq 0 ]
then
	echo "No uninstall specified"
	exit 1
fi

if [ -z "${SCRIPTDIR}" ]
then
	SCRIPTDIR="."
fi

if [ -z "${BINDIR}" ]
then
	BINDIR="${SCRIPTDIR}"
fi

if [ "${OPTION_REMOVE_PREFERENCES}" -ne 0 ]
then
	OPTION_CLEAR_PREFERENCES=0
fi

if ! [ -z "${VOLUME}" ]
then
	VOLUME="/Volumes/${VOLUME}"
fi

# ----------------------------------------------------------------------

if ! [ "${VERBOSE}" -eq 0 ]
then
	echo "Args"	> /dev/stderr
	echo "   "  > /dev/stderr
	echo "   WHAT=            ${WHAT[@]}"	> /dev/stderr
	echo "   HOW=             ${HOW}"		> /dev/stderr
	echo "   SHOW=            ${SHOW}"		> /dev/stderr
	echo "   VOLUME=          '${VOLUME}'"	> /dev/stderr
	echo "   BINDIR=          ${BINDIR}"	> /dev/stderr
	echo "   SCRIPTDIR=       ${SCRIPTDIR}"	> /dev/stderr
	echo "   "								> /dev/stderr
	echo "   INSTALLER=       ${INSTALLER}"	> /dev/stderr
	echo "   CLEAR_PREFS=     ${OPTION_CLEAR_PREFERENCES}"	> /dev/stderr
	echo "   REMOVE_PREFS=    ${OPTION_REMOVE_PREFERENCES}"	> /dev/stderr
	echo "   REMOVE_INSTALLER=${OPTION_REMOVE_INSTALLER}"	> /dev/stderr
	echo "   "  > /dev/stderr
fi

# ----------------------------------------------------------------------
# sam levin - macmice - dlink adapter for bluetooth

source "${SCRIPTDIR}/UninstallerTools.sh"

defineRemoveArgs "${BINDIR}" "${HOW}" "${VOLUME}" "${SHOW}"
locateTools


if ! [ "${VERBOSE}" -eq 0 ]
then
	showRemoveArgs
	# showRemoveTools
fi

# -----------------------------------------------------------------------
# Determine what's installed

# Needed to get RECEIPTS location on specified volume
# TODO - best way to determine what's installed is - are any files for a component installed.

defineInstallLocations "IOXperts" "IOXperts"

HAS_IIDC=0
HAS_WEBCAM=0
HAS_INDUSTRIAL=0
HAS_LOGITECH=0
HAS_WIRELESS=0
HAS_STILL=0

#  NOTE - Determine what's installed by 
#  Note that pkg file names are versioned after 1.1b42

if [ 1 -eq 0 ]
then

	checkForReceipt "WebCam*"
	if test $? -ne 0
	then
		HAS_WEBCAM=1
	fi

	checkForReceipt "Webcam*"
	if test $? -ne 0
	then
		HAS_WEBCAM=1
	fi

	checkForReceipt "IIDC*"
	if test $? -ne 0
	then
		HAS_IIDC=1
	fi

	checkForReceipt "Industrial*"
	if test $? -ne 0 
	then
		HAS_INDUSTRIAL=1
	fi

	checkForReceipt "QuickCam*"
	if test $? -ne 0
	then
		HAS_LOGITECH=1
	fi
	# checkForReceipt "Still"
	# checkForReceipt "Wireless"

fi

# -----------------------------------------------------------------------
# Determine what to remove

REMOVE_DM=0
REMOVE_IIDC=0
REMOVE_INDUSTRIAL=0
REMOVE_INDUSTRIAL_CODECS=0
REMOVE_LOGITECH=0
REMOVE_LOGITECH_KEXTS=0
REMOVE_LOGITECH_DM=0
REMOVE_REGISTER=0
REMOVE_SGPANEL=0
REMOVE_STILL=0
REMOVE_STMICRO_STILL=0
REMOVE_VIDEO_COMMON=0
REMOVE_VIDEO_KEXTS=0
REMOVE_WEBCAM=0
REMOVE_WEBCAM_CODECS=0
REMOVE_WIRELESS=0


# -----------------------------------------------------------------------
# Determine what to remove

for ITEM in "${WHAT[@]}"
do
	# echo "Item=${ITEM}"  > /dev/stderr
	
	# -----------------------------------------------------------------
	# Composite items

	if [[ "${ITEM}" == "webcam" || "${ITEM}" == "usbwebcam" ]]
	then
		REMOVE_WEBCAM=1
		REMOVE_SGPANEL=1
		REMOVE_VIDEO_COMMON=1
		REMOVE_REGISTER=1
		REMOVE_WEBCAM_CODECS=1
		REMOVE_DM=1
		REMOVE_VIDEO_KEXTS=1
		
	elif  [ "${ITEM}" == "iidc" ]
	then
		REMOVE_IIDC=1
		REMOVE_SGPANEL=1
		REMOVE_VIDEO_COMMON=1
		REMOVE_REGISTER=1
		REMOVE_DM=1

	elif [[ "${ITEM}" == "industrial" ]]
	then
		REMOVE_INDUSTRIAL=1
		REMOVE_SGPANEL=1
		REMOVE_VIDEO_COMMON=1
		REMOVE_REGISTER=1
		REMOVE_WEBCAM_CODECS=1
		REMOVE_INDUSTRIAL_CODECS=1
		REMOVE_DM=1
		REMOVE_VIDEO_KEXTS=1

	elif  [ "${ITEM}" == "still" ]
	then
		REMOVE_STILL=1
		REMOVE_REGISTER=1
		REMOVE_DM=1

	elif [[ "${ITEM}" == "wireless" ]]
	then
		REMOVE_WIRELESS=1
		REMOVE_REGISTER=1
		REMOVE_DM=1

	elif [[ "${ITEM}" == "logitech" ]]
	then
		REMOVE_LOGITECH=1
		REMOVE_DM=1
		REMOVE_LOGITECH_DM=1
		REMOVE_LOGITECH_KEXTS=1

	elif  [ "${ITEM}" == "stmicro" ]
	then
		REMOVE_STMICRO_STILL=1
		# REMOVE_REGISTER=1
		# REMOVE_DM=1

	elif [[ "${ITEM}" == "all" ]]
	then
		REMOVE_WEBCAM=1
		REMOVE_IIDC=1
		REMOVE_INDUSTRIAL=1
		REMOVE_WIRELESS=1
		REMOVE_STILL=1
		
		REMOVE_LOGITECH=1
		REMOVE_LOGITECH_KEXTS=1

		REMOVE_STMICRO_STILL=1
		
		REMOVE_VIDEO_COMMON=1
		REMOVE_SGPANEL=1
		REMOVE_VIDEO_KEXTS=1
		REMOVE_REGISTER=1
		REMOVE_INDUSTRIAL_CODECS=1
		REMOVE_WEBCAM_CODECS=1
		REMOVE_DM=1

	elif [[ "${ITEM}" == "ioxperts" ]]
	then
		REMOVE_WEBCAM=1
		REMOVE_IIDC=1
		REMOVE_INDUSTRIAL=1
		REMOVE_WIRELESS=1
		REMOVE_STILL=1
		
		REMOVE_VIDEO_COMMON=1
		REMOVE_SGPANEL=1
		REMOVE_VIDEO_KEXTS=1
		REMOVE_REGISTER=1
		REMOVE_INDUSTRIAL_CODECS=1
		REMOVE_WEBCAM_CODECS=1
		REMOVE_DM=1


	# -----------------------------------------------------------------
	# Individual items
	
	elif [ "${ITEM}" == "webcam-vdigs" ]
	then
		REMOVE_WEBCAM=1

	elif [ "${ITEM}" == "iidc-vdigs" ]
	then
		REMOVE_IIDC=1

	elif [ "${ITEM}" == "industrial-vdigs" ]
	then
		REMOVE_INDUSTRIAL=1

	elif [ "${ITEM}" == "logitech-vdigs" ]
	then
		REMOVE_LOGITECH=1

	elif [ "${ITEM}" == "wireless-kexts" ]
	then
		REMOVE_WIRELESS=1

	elif [ "${ITEM}" == "still-capture" ]
	then
		REMOVE_STILL=1

	elif [ "${ITEM}" == "stmicro-still-capture" ]
	then
		REMOVE_STMICRO_STILL=1

	elif [[ "${ITEM}" == "shared" || "${ITEM}" == "common" ]]
	then
		REMOVE_VIDEO_COMMON=1

	elif [[ "${ITEM}" == "register" || "${ITEM}" == "purchase" ]]
	then
		REMOVE_REGISTER=1
	
	elif [[ "${ITEM}" == "DM" || "${ITEM}" == "dm" ]]
	then
		REMOVE_DM=1
	
	elif [[ "${ITEM}" == "Logitech-DM" || "${ITEM}" == "logitech-dm" ]]
	then
		REMOVE_LOGITECH_DM=1
	
	elif [[ "${ITEM}" == "sgpanel" ]]
	then
		REMOVE_SGPANEL=1
	
	elif [[ "${ITEM}" == "codecs" ]]
	then
		REMOVE_WEBCAM_CODECS=1
	
	elif [[ "${ITEM}" == "industrial-codecs" ]]
	then
		REMOVE_INDUSTRIAL_CODECS=1
	
	elif [[ "${ITEM}" == "video-kexts" ]]
	then
		REMOVE_VIDEO_KEXTS=1
	
	elif [[ "${ITEM}" == "logitech-kexts" ]]
	then
		REMOVE_LOGITECH_KEXTS=1

	fi

done

# -----------------------------------------------------------------------
# Determine what to retain
# If multiple products installed, don't remove shared components unless
# UNLESS we are in installer 


# -------------------------------------------------------------
# Show what will be procesed

if ! [ "${VERBOSE}" -eq 0 ]
then
	echo "    REMOVE_DM=${REMOVE_DM}"							> /dev/stderr
	echo "    REMOVE_IIDC=${REMOVE_IIDC}"						> /dev/stderr
	echo "    REMOVE_INDUSTRIAL=${REMOVE_INDUSTRIAL}"			> /dev/stderr
	echo "    REMOVE_INDUSTRIAL_CODECS=${REMOVE_INDUSTRIAL_CODECS}" > /dev/stderr
	echo "    REMOVE_LOGITECH=${REMOVE_LOGITECH}"				> /dev/stderr
	echo "    REMOVE_LOGITECH_DM=${REMOVE_LOGITECH_DM}"			> /dev/stderr
	echo "    REMOVE_LOGITECH_KEXTS=${REMOVE_LOGITECH_KEXTS}"   > /dev/stderr
	echo "    REMOVE_REGISTER=${REMOVE_REGISTER}"				> /dev/stderr
	echo "    REMOVE_SGPANEL=${REMOVE_SGPANEL}"					> /dev/stderr
	echo "    REMOVE_STILL=${REMOVE_STILL}"						> /dev/stderr
	echo "    REMOVE_STMICRO_STILL=${REMOVE_STMICRO_STILL}"     > /dev/stderr
	echo "    REMOVE_VIDEO_COMMON=${REMOVE_VIDEO_COMMON}"		> /dev/stderr
	echo "    REMOVE_VIDEO_KEXTS=${REMOVE_VIDEO_KEXTS}"			> /dev/stderr
	echo "    REMOVE_WEBCAM=${REMOVE_WEBCAM}"					> /dev/stderr
	echo "    REMOVE_WEBCAM_CODECS=${REMOVE_WEBCAM_CODECS}"		> /dev/stderr
	echo "    REMOVE_WIRELESS=${REMOVE_WIRELESS}"				> /dev/stderr
	echo "    "
fi


# -----------------------------------------------------------------------------------------
# Process IOXperts Installations
# -----------------------------------------------------------------------------------------

if ! [ "${VERBOSE}" -eq 0 ]
then
	echo "Removing Files"	> /dev/stderr
fi

# -------------------------------------------------------------
# Define directories for IOXperts Installations

defineInstallLocations "IOXperts" "IOXperts"

# -------------------------------------------------------------
# Kill running apps as appropriate


echo ">>>>>>Before Killing Apps"


if [ "${REMOVE_REGISTER}" != 0 ]
then
	killRegisterApp
fi
if [[ "${REMOVE_REGISTER}" != 0 || "${REMOVE_VIDEO_COMMON}" != 0 ]]
then
	killSessionMonitor
fi
if [ "${REMOVE_DM}" != 0 ]
then
	killDeviceMonitor
fi
if [ "${REMOVE_LOGITECH_DM}" != 0 ]
then
	killDeviceMonitor logitech
fi

# -------------------------------------------------------------
# IOXperts Register
#

echo ">>>>>>Before REMOVE_REGISTER"

if [ "${REMOVE_REGISTER}" != 0 ]
then	
	removeActionVariants "${APPLICATION_SUPPORT_DIR}/IOXperts Register"		  ".app"
	removeActionVariants "${APPLICATION_SUPPORT_DIR}/IOXperts Purchase"		  ".app"

	# Application Support/bin  - 1.1b43 and later
	removeActionVariants "${APPLICATION_SUPPORT_BIN_DIR}/IOXperts Register"   ".app"

	# Interrim betas 1.1b42-b43
	removeActionVariants "${APPLICATION_SUPPORT_BIN_DIR_OLD}/IOXperts Register"   ".app"
	removeActionVariants "${APPLICATION_SUPPORT_BIN_DIR_OLD_2}/IOXperts Register" ".app"

	# Prefs for sessiond
	if [ "${OPTION_REMOVE_PREFERENCES}" != 0 ]
	then
		removeActionGlob "${PREFERENCES_DIR}/com.ioxperts.common.plist"
		removeActionGlob "${PREFERENCES_DIR}/com.ioxperts.common.1.1.plist"
	fi
	
	# Prefs for sessiond
	if [ "${OPTION_CLEAR_PREFERENCES}" != 0 ]
	then
		echo "    TODO - clear any launch prefs for Purchase/Register"	 > /dev/stderr
	fi
	
fi

# -------------------------------------------------------------
# IOXpers Video Common
#

echo ">>>>>>Before REMOVE_VIDEO_COMMON"

if [ "${REMOVE_VIDEO_COMMON}" != 0 ]
then	
	# Applications/IOXperts
	removeActionVariants "${APPLICATION_DIR}/IOXperts Camera Control"		  ".app"
	removeActionVariants "${APPLICATION_DIR}/Camera Identifier"				  ".app"
	removeActionVariants "${APPLICATION_DIR}/IOXperts Camera Identifier"	  ".app"
	
	# Application Support
	removeActionVariants "${APPLICATION_SUPPORT_DIR}/ioxsessiond"             ".app"
	removeActionVariants "${APPLICATION_SUPPORT_DIR}/SetInstallationPrefs"    ""

	# Application Support/bin  - 1.1b43 and later
	removeActionVariants "${APPLICATION_SUPPORT_BIN_DIR}/ioxsessiond"         ".app"
	
	# Interrim betas 1.1b42-b43
	removeActionVariants "${APPLICATION_SUPPORT_BIN_DIR_OLD}/ioxsessiond"     ".app"
	removeActionVariants "${APPLICATION_SUPPORT_BIN_DIR_OLD_2}/ioxsessiond"   ".app"

	# Kexts
	removeActionVariants "${SYSTEM_EXTENSIONS_DIR}/IOXpertsWebCam"			  ".kext"
	removeActionVariants "${SYSTEM_EXTENSIONS_DIR}/IOXpertsWebcam"			  ".kext"
	
	# Remove prefs for sessiond
	if [ "${OPTION_REMOVE_PREFERENCES}" != 0 ]
	then
		removeActionGlob "${PREFERENCES_DIR}/com.ioxperts.common.plist"
		removeActionGlob "${PREFERENCES_DIR}/com.ioxperts.common.1.1.plist"
	fi
	
	# Prefs for sessiond
	if [ "${OPTION_CLEAR_PREFERENCES}" != 0 ]
	then
		echo "    TODO - clear our login item from loginwindow.plist"	 > /dev/stderr
		echo "    TODO - clear global launch prefs for SM/Identifier/"	 > /dev/stderr
	fi
	
fi

# -------------------------------------------------------------

echo ">>>>>>Before REMOVE_DM"

if [ "${REMOVE_DM}" != 0 ]
then	
	# /Library/StartupItems
	# /System/Library/StartupItems  - 1.1 - Sept 04 and later
	removeAction         "${STARTUP_ITEMS}/IOXpertsDeviceMonitor"
	removeAction         "${SYSTEM_STARTUP_ITEMS}/IOXpertsDeviceMonitor"
	
	# Application Support  - 1.1 - Sept 04 and earlier
	removeActionVariants "${APPLICATION_SUPPORT_DIR}/IOXperts Device Monitor" ".app"

	# Prefs for DM
	if [ "${OPTION_REMOVE_PREFERENCES}" != 0 ]
	then
		removeActionGlob "${PREFERENCES_DIR}/com.ioxperts.devicemonitor.plist"
	fi
	
	# Clear Prefs for DM
	if [ "${OPTION_CLEAR_PREFERENCES}" != 0 ]
	then
		echo "    TODO - save (mvmac) to new filename"
		# "${PREFERENCES_DIR}/com.ioxperts.devicemonitor.plist"
	fi
fi

# -------------------------------------------------------------

echo ">>>>>>Before REMOVE_LOGITECH_DM"

if [ "${REMOVE_LOGITECH_DM}" != 0 ]
then
	# /Library/StartupItems
	removeAction         "${STARTUP_ITEMS}/LogitechDeviceMonitor"

	# Prefs for DM
	if [ "${OPTION_REMOVE_PREFERENCES}" != 0 ]
	then
		removeActionGlob "${PREFERENCES_DIR}/com.logitech.devicemonitor.plist"
	fi
	
fi

# -------------------------------------------------------------
# Remove application dir if emptied

echo ">>>>>>Before Remove empty APPLICATION_DIR"
removeEmptyDir "${APPLICATION_DIR}"

# -------------------------------------------------------------
# Remove applications support bin dir if emptied

echo ">>>>>>Before Remove empty APPLICATION_SUPPORT_BIN_DIR '${APPLICATION_SUPPORT_BIN_DIR}'"
removeEmptyDir "${APPLICATION_SUPPORT_BIN_DIR}"

echo ">>>>>>Before Remove empty APPLICATION_SUPPORT_BIN_DIR_OLD '${APPLICATION_SUPPORT_BIN_DIR_OLD}'"
removeEmptyDir "${APPLICATION_SUPPORT_BIN_DIR_OLD}"

echo ">>>>>>Before Remove empty APPLICATION_SUPPORT_BIN_DIR_OLD_2 '${APPLICATION_SUPPORT_BIN_DIR_OLD_2}'"
removeEmptyDir "${APPLICATION_SUPPORT_BIN_DIR_OLD_2}"


# -------------------------------------------------------------
# Remove Kexts Below here
# -------------------------------------------------------------

echo ">>>>>>Before REMOVE_VIDEO_KEXTS"

if [ "${REMOVE_VIDEO_KEXTS}" != 0 ]
then
	removeAction "${SYSTEM_EXTENSIONS_DIR}/IOXpertsWebcam.kext"
fi

# -------------------------------------------------------------

echo ">>>>>>Before REMOVE_LOGITECH_KEXTS"

if [ "${REMOVE_LOGITECH_KEXTS}" != 0 ]
then
	removeAction "${SYSTEM_EXTENSIONS_DIR}/LogitechQuickCam.kext"
fi

# -------------------------------------------------------------
# Remove Components Below here
# -------------------------------------------------------------

echo ">>>>>>Before REMOVE_SGPANEL"

if [ "${REMOVE_SGPANEL}" != 0 ]
then
	removeActionVariants "${COMPONENTS_DIR}/IOXperts SGPanel"		  ".component"
	removeActionVariants "${COMPONENTS_DIR}/IOXperts Video Support"	  ".component"
	
	# Prefs for sessiond
	if [ "${OPTION_REMOVE_PREFERENCES}" != 0 ]
	then
		echo " "
	fi

	# Clear Prefs for DM
	if [ "${OPTION_CLEAR_PREFERENCES}" != 0 ]
	then
		echo " "
		# "${PREFERENCES_DIR}/com.ioxperts.devicemonitor.plist"
	fi
fi

# -------------------------------------------------------------

echo ">>>>>>Before REMOVE_WEBCAM_CODECS"

if [ "${REMOVE_WEBCAM_CODECS}" != 0 ]
then
	removeAction "${COMPONENTS_DIR}/IOXperts IIDC Codec.component"
fi

# -------------------------------------------------------------

echo ">>>>>>Before REMOVE_INDUSTRIAL_CODECS"

if [ "${REMOVE_INDUSTRIAL_CODECS}" != 0 ]
then
	removeAction "${COMPONENTS_DIR}/IOXperts Bayer Codec.component"
fi

# -------------------------------------------------------------

echo ">>>>>>Before REMOVE_WEBCAM"

if [ "${REMOVE_WEBCAM}" != 0 ]
then

	removeActionVariants "${COMPONENTS_DIR}/IOXperts WebCam" ".component"
	removeActionVariants "${COMPONENTS_DIR}/IOXperts Webcam" ".component"
	
	removeActionCustomizedComponents

	if [ "${OPTION_REMOVE_PREFERENCES}" != 0 ]
	then
		echo "    TODO - find and remove Webcam Prefs"			> /dev/stderr
		removeActionGlob "${PREFERENCES_DIR}/com.ioxperts.webcam*"
		removeActionGlob "${HOME_PREFERENCES_DIR}/com.ioxperts.*"
	fi
	
	# Prefs for sessiond
	if [ "${OPTION_REMOVE_INSTALLER}" != 0 ]
	then
		removeActionGlob "${RECEIPTS_DIR}/WebCam*.pkg"
		removeActionGlob "${RECEIPTS_DIR}/Webcam*.pkg"
	fi
	
fi

# -------------------------------------------------------------

echo ">>>>>>Before REMOVE_IIDC"

if [ "${REMOVE_IIDC}" != 0 ]
then
	
	# Library/Components
	removeActionVariants "${COMPONENTS_DIR}/IOXperts FWDCam" ".component"
	removeActionCustomizedComponents
	
	# Prefs for sessiond
	if [ "${OPTION_REMOVE_INSTALLER}" != 0 ]
	then
		removeActionGlob "${RECEIPTS_DIR}/IIDC*.pkg"
	fi
fi

# -------------------------------------------------------------

echo ">>>>>>Before REMOVE_INDUSTRIAL"

if [ "${REMOVE_INDUSTRIAL}" != 0 ]
then
	removeActionVariants "${COMPONENTS_DIR}/IOXperts Industrial Camera" ".component"
	
	# Prefs for sessiond
	if [ "${OPTION_REMOVE_INSTALLER}" != 0 ]
	then
		removeActionGlob "${RECEIPTS_DIR}/Industrial*.pkg"
	fi
	
fi

# -------------------------------------------------------------

echo ">>>>>>Before REMOVE_STILL"

if [ "${REMOVE_STILL}" != 0 ]
then
	echo "    TODO - find and remove still, " > /dev/stderr
	# removeActionVariants "${IMAGE_CAPTURE_DIR}/USBStillCamera"				 ".app"
	# removeActionVariants "${IMAGE_CAPTURE_DIR}/IOXpertsUSBStillCamera-Logging" ".app"
fi

# -------------------------------------------------------------

echo ">>>>>>Before REMOVE_WIRELESS"

if [ "${REMOVE_WIRELESS}" != 0 ]
then
	echo "    TODO - find and remove wireless kexts, components, " > /dev/stderr

	if [ "${OPTION_REMOVE_PREFERENCES}" != 0 ]
	then
		echo "    TODO - find and remove wireless Prefs" > /dev/stderr
	fi
	
	if [ "${OPTION_CLEAR_PREFERENCES}" != 0 ]
	then
		echo "    TODO - clear specific prefs that affect the new wireless installation." > /dev/stderr
	fi
	
	# Prefs for sessiond
	if [ "${OPTION_REMOVE_INSTALLER}" != 0 ]
	then
		echo "    TODO - find and remove wireless pkg" > /dev/stderr
		# removeActionGlob "${RECEIPTS_DIR}/WebCam*.pkg"
	fi
	
fi

# -----------------------------------------------------------------------------------------
# Process STMicro Installations
# -----------------------------------------------------------------------------------------

echo ">>>>>>Before STMicro"

defineInstallLocations "IOXperts" "IOXperts"

# -------------------------------------------------------------

echo ">>>>>>Before REMOVE_STMICRO_STILL"

if [ "${REMOVE_STMICRO_STILL}" != 0 ]
then
	echo "    TODO - find and remove stmicro still, " > /dev/stderr
	# removeActionVariants "${IMAGE_CAPTURE_DIR}/USBStillCamera"				 ".app"
	# removeActionVariants "${IMAGE_CAPTURE_DIR}/IOXpertsUSBStillCamera-Logging" ".app"
fi


# -----------------------------------------------------------------------------------------
# Process Logitech Installations
# -----------------------------------------------------------------------------------------
# Logitech is in a separate section because it uses has its own Application and Application Support
# directories.

echo ">>>>>>Before Logitech"

defineInstallLocations "Logitech QuickCam" "Logitech"

# -------------------------------------------------------------
# NOTE - Logitech QuickCam also requires removal of the DM for
#		 clean removal.
# NOTE - Logitech does not use SM, Register, Purchase, or Identifier App.

echo ">>>>>>Before REMOVE_LOGITECH"

if [ "${REMOVE_LOGITECH}" != 0 ]
then
	
	removeActionVariants "${APPLICATION_DIR}/Logitech Camera Control"		".app"
	removeActionVariants "${APPLICATION_DIR}/QuickCapture"					".app"
	removeActionVariants "${APPLICATION_SUPPORT_DIR}/SetInstallationPrefs"	""
	removeActionVariants "${COMPONENT_DIR}/Logitech QuickCam"				".qtx"
	# TODO - separate removal for logitech kexts
	removeActionVariants "${SYSTEM_EXTENSIONS_DIR}/LogitechQuickCam"		".kext"

	# Preferences
	if [ "${OPTION_REMOVE_PREFERENCES}" != 0 ]
	then
		removeActionGlob "${PREFERENCES_DIR}/com.logitech.*"
		removeActionGlob "${HOME_PREFERENCES_DIR}/com.logitech.*"
	fi
	
	# Installer
	if [ "${OPTION_REMOVE_INSTALLER}" != 0 ]
	then
		removeActionGlob "${RECEIPTS_DIR}/QuickCam*.pkg"
	fi

fi


# -------------------------------------------------------------
# Remove application dir if emptied

echo ">>>>>>Before Logitech Remove APPLICATION_DIR '${APPLICATION_DIR}'"
removeEmptyDir "${APPLICATION_DIR}"

# -------------------------------------------------------------
# Remove applications support bin dir if emptied

if [ 1 -eq 0 ]
then

	echo ">>>>>>Before Logitech Remove empty APPLICATION_SUPPORT_BIN_DIR '${APPLICATION_SUPPORT_BIN_DIR}'"
	removeEmptyDir "${APPLICATION_SUPPORT_BIN_DIR}"

	echo ">>>>>>Before Logitech Remove empty APPLICATION_SUPPORT_BIN_DIR_OLD '${APPLICATION_SUPPORT_BIN_DIR_OLD}'"
	removeEmptyDir "${APPLICATION_SUPPORT_BIN_DIR_OLD}"

	echo ">>>>>>Before Logitech Remove empty APPLICATION_SUPPORT_BIN_DIR_OLD_2 '${APPLICATION_SUPPORT_BIN_DIR_OLD_2}'"
	removeEmptyDir "${APPLICATION_SUPPORT_BIN_DIR_OLD_2}"

fi


